package com.kotlin.book.api

import HttpApi
import com.google.gson.reflect.TypeToken
import com.kotlin.book.entry.Book

object BookApi {
    fun getRecommendList(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Book>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Book>>>() {}.type
        HttpApi.get<List<Book>>(
            "/book/getRecommendList",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getHotList(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Book>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Book>>>() {}.type
        HttpApi.get<List<Book>>(
            "/book/getHotList",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getWeekList(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Book>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Book>>>() {}.type
        HttpApi.get<List<Book>>(
            "/book/getWeekList",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getClassList(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Book>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Book>>>() {}.type
        HttpApi.get<List<Book>>(
            "/book/getClassList",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getBookListByAuthor(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Book>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Book>>>() {}.type
        HttpApi.get<List<Book>>(
            "/book/getBookListByAuthor",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getRandBookList(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<List<Book>>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<List<Book>>>() {}.type
        HttpApi.get<List<Book>>(
            "/book/getRandBookList",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }

    fun getBookDetail(
        param: Map<String, Any?>?,
        callback: (HttpApi.ApiResponse<Book>?) -> Unit
    ) {
        val type = object : TypeToken<HttpApi.ApiResponse<Book>>() {}.type
        HttpApi.get<Book>(
            "/book/getBookDetail",
            param ?: mapOf(),
            type
        ) { response ->
            response?.let { callback(it) } ?: callback(null)
        }
    }
}